home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CSCROLLL / CSCROLLL.C < prev    next >
Text File  |  1992-02-19  |  4KB  |  168 lines

  1. /*************************************************************************************
  2.  
  3.  CScrollListDragger.c
  4.     
  5.         Used with scrolling lists that allow the movement of array elements
  6.         within the list.
  7.     
  8.     SUPERCLASS = CMouseTask
  9.     
  10.         by Dave Harkness
  11.  
  12. *************************************************************************************/
  13.  
  14.  
  15. #include "CScrollListDragger.h"
  16. #include "CScrollList.h"
  17. #include "CArray.h"
  18. #include "TBUtilities.h"
  19.  
  20.  
  21. /******************************************************************************
  22.  IScrollListDragger
  23.  
  24.      Initialize a CScrollListDragger. theModifers should be the modifier flags
  25.      from DoClick. selFlags should be the table's selection flags.
  26. ******************************************************************************/
  27.  
  28. void
  29. CScrollListDragger::IScrollListDragger( CScrollList *aTable,
  30.                                         short theModifiers, long selFlags)
  31. {
  32.     CMouseTask::IMouseTask( 0);
  33.     
  34.     itsTable = aTable;
  35.     itsArray = (CArray *)itsTable->GetArray();
  36.     selectionFlags = selFlags;
  37.     modifierKeys = theModifiers;
  38.     
  39.     SetCell( movingCell, 0, 0);
  40.     
  41. }    /* CScrollListDragger::IScrollListDragger */
  42.  
  43.  
  44. /******************************************************************************
  45.  Dispose
  46.       
  47.       Dispose of a CScrollListDragger. This method clears the table's reference to
  48.       this task.
  49. ******************************************************************************/
  50.  
  51. void
  52. CScrollListDragger::Dispose(void)
  53. {
  54.     if (itsTable->itsLastTask == this)
  55.         itsTable->itsLastTask = NULL;
  56.         
  57.     inherited::Dispose();
  58. }
  59.  
  60.  
  61. /******************************************************************************
  62.  BeginTracking  {OVERRIDE}
  63.  
  64.     Called at the start of mouse tracking. This method selects the cell
  65.     being dragged and calculates the rectangle to drag.
  66. ******************************************************************************/
  67.  
  68. void CScrollListDragger::BeginTracking( LongPt *startPt)
  69. {
  70.     Cell        aCell;
  71.     LongRect    aBounds;
  72.     Rect        qdRect;
  73.     
  74.     itsTable->FindHitCell( startPt, &aCell);
  75.     itsTable->SelectCell( aCell, FALSE, TRUE);
  76.         
  77.     movingCell = aCell;
  78.     
  79.     itsTable->GetCellRect( aCell, &dragRect);
  80.     OffsetLongRect( &dragRect, 0, startPt->v - ((dragRect.top + dragRect.bottom) >> 1));
  81.     
  82.     itsTable->GetBounds( &aBounds);
  83.     SetLongRect( &clipRect, dragRect.left, aBounds.top, dragRect.right, aBounds.bottom);
  84.     
  85.     itsTable->FrameToQDR( &dragRect, &qdRect);
  86.     PenPat( gray);
  87.     PenMode( patXor);
  88.     FrameRect( &qdRect);
  89.     
  90. }    /* CScrollListDragger::BeginTracking */
  91.  
  92.  
  93. /******************************************************************************
  94.  KeepTracking  {OVERRIDE}
  95.  
  96.      Called continously while the mouse button is held down. This method
  97.      continously draws a gray rectangle and autoscrolls the table.
  98. ******************************************************************************/
  99.  
  100. void
  101. CScrollListDragger::KeepTracking(LongPt *currPt, LongPt *prevPt, LongPt *startPt)
  102. {
  103.     long        curTicks;
  104.     Rect        qdRect;
  105.     
  106.     PinInRect( &clipRect, prevPt);
  107.     PinInRect( &clipRect, currPt);
  108.     
  109.     if (currPt->v != prevPt->v)
  110.     {
  111.         itsTable->FrameToQDR( &dragRect, &qdRect);
  112.         PenPat( gray);
  113.         PenMode( patXor);
  114.         
  115.         for ( curTicks = TickCount(); curTicks == TickCount(); )
  116.             /* try to avoid flicker */ ;
  117.         FrameRect( &qdRect);
  118.         
  119.         itsTable->AutoScroll( currPt);
  120.         OffsetLongRect( &dragRect, 0, currPt->v - prevPt->v);
  121.         
  122.         itsTable->FrameToQDR( &dragRect, &qdRect);
  123.         PenPat( gray);
  124.         PenMode( patXor);
  125.         
  126.         for ( curTicks = TickCount(); curTicks == TickCount(); )
  127.             /* try to avoid flicker */ ;
  128.         FrameRect( &qdRect);
  129.     }
  130.  
  131. }    /* CScrollListDragger::KeepTracking */
  132.  
  133.  
  134. /******************************************************************************
  135.  EndTracking  {OVERRIDE}
  136.  
  137.      Erase the dragging rectangle.
  138. ******************************************************************************/
  139.  
  140. void
  141. CScrollListDragger::EndTracking(LongPt *currPt, LongPt *prevPt, LongPt *startPt)
  142. {
  143.     Rect        qdRect;
  144.     Cell        endCell;
  145.     Str255        str;
  146.     
  147.     itsTable->FrameToQDR( &dragRect, &qdRect);
  148.     PenPat( gray);
  149.     PenMode( patXor);
  150.     FrameRect( &qdRect);
  151.     
  152.     itsTable->FindHitCell( currPt, &endCell);
  153.     if ( currPt->v - itsTable->GetRowStart( endCell.v) >=
  154.                     itsTable->GetRowHeight( endCell.v) >> 1 )
  155.         ++endCell.v;
  156.     
  157.     if ( endCell.v > movingCell.v)
  158.         --endCell.v;
  159.     
  160.     if ( endCell.v != movingCell.v )
  161.     {
  162.         itsArray->MoveItemToIndex( movingCell.v+1, endCell.v+1);
  163.         itsTable->SelectCell( endCell, FALSE, TRUE);
  164. //        itsTable->DoCommand( cmdMakeMeDirty);
  165.     }
  166.     
  167. }    /* CScrollListDragger::KeepTracking */
  168.